<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			
		window.onload=function(){
			
			var a=document.getElementById('a');
			var arr=["苹果","香蕉","芒果"]
			for(var i=0;i<arr.length;i++){
				var li=document.createElement("li");
				li.innerHTML=arr[i];
				a.appendChild(li);
			}
			var li=a.getElementsByTagName('li');
			for(var i=0;i<li.length;i++){
				li[i].onclick=function(){
					alert(this.innerHTML);
				}
			}
			function Trim(a)
			{ 
  				return a.replace(/(^\s*)|(\s*$)/g, ""); 
			}
			var sub=document.getElementById('sub');
			var txt=document.getElementById('txt1');
			sub.onclick=function(){
					if(Trim(txt.value)==''){
						alert("输入内容")
					}else{
						var li=document.createElement('li');
						li.innerHTML=txt.value;
						var city=document.getElementById('b');
						city.appendChild(li);
					}
				}
			
		}
		
		</script>
	</head>
	<body>
		<ul id="a">
			
		</ul>
		<ul id="b">
			
		</ul>
		<input type="txt" name="" id="txt1" value="" />
		<input type="submit" name="" id="sub" value="提交" />
	</body>
</html>
